import request from "../request/main";

export interface changePost {
  title: string;
  content: string;
  image?: string;
}

export interface addPost {
  title: string;
  content: string;
  column?: string;
  author?: string;
  image?: string;
}

export interface changeColumn {
  title: string;
  description: string;
  avatar?: string;
}

export interface loginType {
  email: string;
  password: string;
}

export interface addUserData {
  email: string;
  nickName: string;
  password: string;
}

export interface changeUsetData {
  _id: string;
  email: string;
  nickName: string;
  description: string;
  avatar: string;
  column: string;
  createdAt?: string;
}

export interface TypeResUserData {
  code: number;
  msg: string;
  data: {
    token: string;
  };
}

export const reqAddPost = (data: addPost) => request.post("posts", data);

export const reqDelPost = (id: string) => request.delete(`posts/${id}`);

export const reqChangePost = (id: string, data: changePost) =>
  request.patch(`posts/${id}`, data);

export const reqSomePost = (id: string) => request.get(`posts/${id}`);

export const reqPostList = (id: string, page: number) =>
  request.get(`columns/${id}/posts?currentPage=${page}&pageSize=5`);

export const reqColumnsList = (page: number) =>
  request.get(`columns?currentPage=${page}&pageSize=6`);

export const reqChangeColumn = (id: number, data: changeColumn) =>
  request.patch(`columns/${id}`, data);

export const reqSomeColumns = (id: string) => request.get(`/columns/${id}`);

export const reqUserLogin = (userData: loginType) =>
  request.post(`user/login`, userData);

export const reqAddUser = (userData: addUserData) =>
  request.post(`users`, userData);

export const reqGetUser = () => request.get("/user/current");

export const reqChangeUset = (id: number, userData: changeUsetData) =>
  request.patch(`user/${id}`, userData);
